package com.example.extest;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ActivitySMS extends Activity {
	
	// @Override
		public void onCreate(Bundle state) {
			super.onCreate(state);
			setContentView(R.layout.sms_layout);
		}
		
		public void sendSMS(){
			Button buttonSend = (Button)findViewById(R.id.buttonSend);
			final EditText textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
			final EditText textSMS = (EditText) findViewById(R.id.editTextSMS);
	 
			buttonSend.setOnClickListener(new OnClickListener() {
	 
				@Override
				public void onClick(View v) {
	 
				  String phoneNo = textPhoneNo.getText().toString();
				  String sms = textSMS.getText().toString();
	 
				  try {
					SmsManager smsManager = SmsManager.getDefault();
					smsManager.sendTextMessage(phoneNo, null, sms, null, null);
					Toast.makeText(getApplicationContext(), "SMS Sent!",
								Toast.LENGTH_LONG).show();
				  } catch (Exception e) {
					Toast.makeText(getApplicationContext(),
						"SMS faild, please try again later!",
						Toast.LENGTH_LONG).show();
					e.printStackTrace();
				  }
	 
				}
			});
		}

}
